package someTestExcemple.netWorkCommunication;

import java.io.IOException;
import java.net.InetAddress;

public class InetAddressTest {
    public static void main(String[] args) throws IOException {
        test1();
    }
    public static void test1() throws IOException {
        //获取本机的ip地址对象
        InetAddress ip1 = InetAddress.getLocalHost();
        System.out.println(ip1);
        System.out.println(ip1.getHostName());
        System.out.println(ip1.getHostAddress());
        InetAddress ip2 = InetAddress.getByName("wwww.baidu.com");
        System.out.println(ip2);
        System.out.println(ip2.getHostName());
        System.out.println(ip2.getHostAddress());
        //判断主机与ip2是否连通
        boolean reachable = ip2.isReachable(5000);
        System.out.println(reachable);
    }
}
